﻿using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Newtonsoft.Json;

namespace music.web.Models.Shared
{
	public class PlaylistModel
	{
		public PlaylistModel()
		{
			Songs = new List<SongModel>();
		}

		/// <summary>
		/// Список песен
		/// </summary>
		public IList<SongModel> Songs { get; set; }

		private object CreateSongDto(SongModel song, UrlHelper url)
		{
			string title = song.FullTitle;
			string mp3 = song.GetFileUrl(url);

			return new { title, mp3 };
		}

		public string GetPlaylistJson(UrlHelper url)
		{
			var list = Songs
				.Select(song => CreateSongDto(song, url))
				.ToList();

			return JsonConvert.SerializeObject(list);
		}
	}
}